@import './variable.scss';
@import './base.scss';
@import './ch-icon.scss';
@import './markdown.scss';
@import './previewer.scss';
@import './print.scss';
@import './bubble_formula.scss';
@import './formula_utils_bubble.scss';
@import './components/shortcut_key_config.scss';

@mixin cherryFont {
  font-family: $fontFamily;
  font-size: $fontSize;
}

// 主要布局控制，可以不合并进下面的区块
.cherry {
  display: flex;
  flex-flow: row wrap;
  align-items: stretch;
  align-content: flex-start;
  height: 100%;
  min-height: 60px;
  position: relative;
  // overflow: hidden;

  .cherry-editor,
  .cherry-previewer {
    max-height: calc(100% - #{$toolbarHeight});
    min-height: calc(100% - #{$toolbarHeight});
  }

  .CodeMirror {
    height: 100%;
  }

  &.cherry--no-toolbar {
    .cherry-toolbar,
    .cherry-sidebar {
      height: 0;
      display: none;
    }

    .cherry-editor,
    .cherry-previewer {
      max-height: 100%;
      min-height: 100%;
    }
  }
}

.cherry {
  @include cherryFont;
  line-height: $lineHeight;
  color: $fontColor;
  background: $editorBg;
  box-shadow: $shadow;

  .ch-icon {
    vertical-align: middle;
  }

  .clearfix {
    zoom: 1;

    &:after {
      content: '.';
      display: block;
      height: 0;
      clear: both;
      visibility: hidden;
      overflow: hidden;
      font-size: 0;
    }
  }

  &.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99;
  }

  .no-select {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  .cherry-insert-table-menu {
    display: block;
    position: fixed;
    // z-index: 100;
    top: 40px;
    left: 40px;
    border-collapse: separate;
    box-shadow: $shadow;
    padding: 4px;
    border-radius: $borderRadius;
    width: auto;
    height: auto;

    &-item {
      padding: 7px;
      border: 1px solid $borderColor;

      &.active {
        background-color: $toolbarBtnBgHoverLight;
      }
    }
  }

  &[data-toolbar-theme='dark'] {
    .cherry-insert-table-menu-item {
      border-color: rgba(255, 255, 255, 0.2);

      &.active {
        background-color: $toolbarBtnColorDark;
      }
    }
  }
}

.cherry-dropdown {
  position: absolute;
  width: 130px;
  min-height: 40px;
  background: #fff;
  //border: 1px solid $borderColor;
  box-shadow: 0 5px 15px -5px rgba(0, 0, 0, 0.5);
  margin-left: -60px;
  z-index: 13;

  &-item {
    width: 100%;
    padding: 0 15px;
    text-align: left;
    display: inline-block;
    height: 36px;
    line-height: 36px;
    font-size: 14px;
    font-style: normal;
    cursor: pointer;
    box-sizing: border-box;

    &:hover {
      background: $toolbarBtnBgHoverLight;
      color: $toolbarBtnHoverColorLight;
    }
    &__selected {
      background: $toolbarBtnBgHoverLight;
      color: $toolbarBtnHoverColorLight;
    }

    .ch-icon {
      margin-right: 10px;
    }
  }

  [data-toolbar-theme='dark'] & {
    background: $toolbarBgDark;

    .cherry-dropdown-item {
      background: $toolbarBtnBgDark;
      color: $toolbarBtnColorDark;

      &:hover {
        background: $toolbarBtnBgHoverDark;
        color: $toolbarBtnHoverColorDark;
      }
      &__selected {
        background: $toolbarBtnBgHoverDark;
        color: $toolbarBtnHoverColorLight;
      }
    }
  }
}

.cherry-toolbar {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 20px;
  min-height: $toolbarHeight;
  font-size: $toolbarFontSize;
  line-height: 2.8;
  flex-basis: 100%;
  box-sizing: border-box;
  z-index: 2;
  user-select: none;
  box-shadow: $toolbarShadowLight;
  background: $toolbarBgLight;
  overflow: hidden;
  .icon-loading {
    &.loading {
      display: inline-block;
      width: 8px;
      height: 8px;
    }

    &.loading:after {
      content: ' ';
      display: block;
      width: 8px;
      height: 8px;
      margin-left: 2px;
      margin-top: -2px;
      border-radius: 50%;
      border: 2px solid #000;
      border-color: #000 transparent #000 transparent;
      animation: loading 1.2s linear infinite;
    }
  }

  [data-toolbar-theme='dark'] & {
    background: $toolbarBgDark;
    box-shadow: $toolbarShadowDark;

    .cherry-toolbar-button {
      color: $toolbarBtnColorDark;
      background: $toolbarBtnBgDark;

      &:hover {
        color: $toolbarBtnHoverColorDark;
        background: $toolbarBtnBgHoverDark;
      }
    }
  }

  .toolbar-left,
  .toolbar-right {
    display: flex;
    align-items: center;
    min-height: $toolbarHeight;
    flex-wrap: wrap;
    flex: 1;
  }

  .toolbar-left {
    margin-right: 20px;
  }

  .toolbar-right {
    flex: 0 1 auto;
    flex-direction: row-reverse;
    margin-left: 10px;
    box-sizing: border-box;
    min-height: 0;
  }

  &.preview-only {
    .cherry-toolbar-button {
      display: none;
    }

    .cherry-toolbar-switchPreview {
      display: inline;
    }
  }

  &-button {
    float: left;
    padding: 0 12px;
    // margin: 4px 0;
    height: 38px;
    color: $toolbarBtnColorLight;
    background: transparent;
    border: 1px solid transparent;
    -webkit-transition: background-color ease-in-out 0.15s, color ease-in-out 0.15s, border-color ease-in-out 0.15s;
    transition: background-color ease-in-out 0.15s, color ease-in-out 0.15s, border-color ease-in-out 0.15s;
    cursor: pointer;
    font-style: normal;

    &:hover {
      color: $toolbarBtnHoverColorLight;
      background: $toolbarBtnBgHoverLight;
    }

    &.cherry-toolbar-split {
      font-size: 0;
      height: 19px;
      padding: 0;
      margin: 9.5px 4px;
      border: 1px solid transparent;
      border-left: 1px solid $toolbarSplitColor;
      pointer-events: none;
      overflow: hidden;
      opacity: 0.5;
    }

    &.disabled {
      color: $toolbarBtnDisabledLight;
    }
  }
}

.cherry {
  .ace_search {
    background: #fff;
  }
}

.cherry-sidebar {
  width: 30px;
  position: absolute;
  top: 48px;
  right: 7px;
  z-index: 11;
  bottom: 0;
  overflow: hidden;

  .cherry-toolbar-button {
    height: 30px;
    padding: 3px 12px 0 6px;

    &:hover {
      background: transparent;
    }

    .icon-loading {
      &.loading {
        display: inline-block;
        width: 8px;
        height: 8px;
      }

      &.loading:after {
        content: ' ';
        display: block;
        width: 8px;
        height: 8px;
        margin-left: 2px;
        margin-top: -2px;
        border-radius: 50%;
        border: 2px solid #000;
        border-color: #000 transparent #000 transparent;
        animation: loading 1.2s linear infinite;
      }
    }

    @keyframes loading {
      0% {
        transform: rotate(0deg);
      }

      100% {
        transform: rotate(360deg);
      }
    }
  }
}

@import './components/bubble';

.cherry-floatmenu {
  z-index: 4;
  display: none;
  position: absolute;
  left: 30px;
  margin-left: 60px;
  height: $lineHeight;
  line-height: $lineHeight;
  border-radius: $borderRadius;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;

  .cherry-toolbar-button {
    float: left;
    padding: 0 9px;
    margin: 0;
    height: $lineHeight;
    line-height: $lineHeight;
    font-size: 14px;
    color: $fontColor;
    overflow: hidden;
    vertical-align: middle;
    text-align: center;
    border: 0;
    cursor: pointer;
    font-style: normal;

    &.cherry-toolbar-split {
      border-left: 1px solid $borderColor;
      width: 0;
      padding: 0;
      overflow: hidden;
      height: 25px;
    }

    .ch-icon {
      color: #aaa;
      font-size: 12px;
    }

    &:hover {
      background: rgba(0, 0, 0, 0.05);

      .ch-icon {
        color: $toolbarBtnColorLight;
      }
    }
  }
}

.cherry-editor {
  position: relative;
  padding-top: 5px;
  padding-right: 5px;
  width: 50%;
  box-sizing: border-box;
  overflow: hidden;

  &.cherry-editor--full {
    width: 100%;
    padding-right: 0;
  }

  &.cherry-editor--hidden {
    display: none;
  }

  &-writing-style {
    &--focus {
      &::before {
        content: '';
        display: block;
        width: 100%;
        position: absolute;
        top: 0;
        background: linear-gradient(to bottom, #00000006, #00000033);
        pointer-events: none;
        z-index: 11;
      }
      &::after {
        content: '';
        display: block;
        width: 100%;
        position: absolute;
        bottom: 0;
        background: linear-gradient(to top, #00000006, #00000033);
        pointer-events: none;
        z-index: 11;
      }
    }
    &--typewriter {
      .CodeMirror-lines {
        position: relative;
        &::before {
          content: '';
          display: block;
        }
        &::after {
          content: '';
          display: block;
        }
      }
    }
  }

  .CodeMirror {
    font-family: $fontFamily;
    background: $editorBg;
    color: $fontColor;

    // codemirror 依赖隐藏的 textarea 计算行高，这里将字体大小设置为行高，避免输入法遮挡内容
    // Fixed https://github.com/Tencent/cherry-markdown/issues/82
    textarea {
      font-size: $lineHeight;
    }
  }

  .CodeMirror-lines {
    padding: 15px 34px;

    // 对draw.io的xml数据，和图片里base64格式的数据限定最大宽度
    .long-text,
    .drawio,
    .base64 {
      display: inline-block;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 80px;
      white-space: nowrap;
      vertical-align: bottom;
      color: darkmagenta !important;
      font-size: 12px !important;
    }
  }

  .cm-s-default .cm-header {
    color: $editorHeaderColor;
  }

  .cm-s-default .cm-string {
    color: $editorStringColor;
  }

  .cm-s-default .cm-comment {
    color: $editorCommentColor;
    font-family: $monospaceFont;
    font-size: 0.9em;
  }

  .cm-s-default .cm-whitespace,
  .cm-tab {
    font-family: $monospaceFont;
    font-size: 0.9em;
  }

  .cm-s-default .cm-quote {
    color: $editorQuoteColor;
  }

  .cm-s-default .cm-link {
    color: $editorLinkColor;
  }

  .cm-s-default .cm-url {
    background: $editorUrlBgColor;
    font-family: $monospaceFont;
    font-size: 0.9em;
  }

  .cm-s-default .cm-variable-2 {
    color: $editorV2Color;
  }

  .cm-s-default .cm-variable-3 {
    color: $editorV3Color;
  }

  .cm-s-default .cm-keyword {
    color: $editorKeywordColor;
  }

  .cm-s-default .cm-fullWidth {
    color: $fullWidthColor;
    z-index: 3;
    cursor: pointer;
  }
}

.cherry-drag {
  width: 15px;
  cursor: ew-resize;
  position: absolute;
  z-index: 12;
  background: transparent;

  &.cherry-drag--show {
    width: 5px;
    display: block;
    background: #dfe6ee;
  }

  &.cherry-drag--hidden {
    display: none;
  }
}

.cherry-editor-mask {
  z-index: 10;
  position: absolute;
  display: none;
  background: rgba(0, 0, 0, 0.2);

  &.cherry-editor-mask--show {
    display: block;
  }
}

.cherry-previewer-mask {
  z-index: 10;
  position: absolute;
  display: none;
  background: rgba(0, 0, 0, 0.4);

  &.cherry-previewer-mask--show {
    display: block;
  }
}

.cherry-previewer-codeBlock-click-handler {
  position: absolute;
  z-index: 1;
}

.cherry-mask-code-block{
  width: 100%;
  padding-top: 50px;
  display: none;
  background-image: -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0)), to(#fff));
  background-image: linear-gradient(-180deg, rgba(255, 255, 255, 0) 0%, #fff 100%);
  text-align: center;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.5em;
  z-index: 10;
  .expand-btn {
    width: 25px;
    height: 25px;
    border: 1px solid #ffffff00;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.3s;
    z-index: 12;
    color: #3582fb;
    background-color: #d7e6fe;
    display: inline-block;
    &:hover {
      color: #eee;
      background-color: #3582fb;
      border-color: #eee;
    }
  }
}


.cherry-code-unExpand{
  pre {
    height: 240px;
    overflow: hidden !important;
  }
  .cherry-mask-code-block {
    display: inline-block;
  }
}

.cherry-previewer-codeBlock-hover-handler {
  z-index: 0;
  position: absolute;
  pointer-events: none;
  * {
    pointer-events: all;
  }
  .cherry-code-block-custom-btn,
  .cherry-copy-code-block,
  .cherry-unExpand-code-block,
  .cherry-edit-code-block {
    position: relative;
    width: 25px;
    text-align: center;
    height: 25px;
    border: 1px solid #3582fb;
    cursor: pointer;
    float: right;
    top: 15px;
    border-radius: 5px;
    // margin-left: -27px;
    transition: all 0.3s;
    z-index: 2;
    color: #3582fb;
    background-color: #eee;
    border-color: #3582fb;
  }
  .cherry-code-block-custom-btn {
    width: auto;
  }
  .cherry-expand-code-block{
    position: absolute;
    width: 25px;
    text-align: center;
    height: 25px;
    border: 1px solid #3582fb;
    cursor: pointer;
    float: right;
    border-radius: 5px;
    margin-left: -27px;
    transition: all 0.3s;
    z-index: 2;
    color: #3582fb;
    background-color: #eee;
    border-color: #3582fb;
  }
  .cherry-expand-code-block {
    top: 45px;
    right:10px;
  }
  .cherry-unExpand-code-block{
    z-index: 12;
    &.hidden {
      display: none;
    }
  }
  .cherry-code-block-custom-btn:hover,
  .cherry-copy-code-block:hover,
  .cherry-expand-code-block:hover,
  .cherry-unExpand-code-block:hover,
  .cherry-edit-code-block:hover {
    color: #eee;
    background-color: #3582fb;
    border-color: #eee;
  }
  .cherry-code-preview-lang-select {
    position: absolute;
    transform: translate(2px, -50%);
  }
}

.float-previewer-wrap {
  position: fixed;
  right: 0;
  top: 0;
  z-index: 100;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.1);
  resize: both;
  min-width: 430px;
  min-height: 300px;

  &.float-previewer-dragging{
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.3);

    .float-previewer-header{
      cursor: grabbing;
      background: #ace4ff;
    }
  }

  .float-previewer-header{
    z-index: 999999;
    height: 40px;
    border-bottom: 1px solid #ebedee;
    background: #caecfd;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    cursor: grab;

    .float-previewer-title{
      user-select: none;
      font-size: 16px;
      color: #333;
      font-weight: bold;
    }
  }

  .cherry-previewer{
    border-left: none;
  }
}

.cherry-previewer {
  padding: 20px 45px 20px 20px;
  border-left: 2px solid #ebedee;
  width: 50%;
  box-sizing: border-box;
  background-color: $previewBg;
  min-height: auto;
  overflow-y: auto;
  -webkit-print-color-adjust: exact;

  .cherry-mobile-previewer-content {
    width: 375px;
    height: 100%;
    margin: 0 auto;
    padding: 25px 30px;
    overflow-y: scroll;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
  }

  &.cherry-previewer--hidden {
    width: 0;
    display: none;
  }

  &.cherry-previewer--full {
    width: 100%;
  }

  .cherry-list__upper-roman {
    list-style: upper-roman;
  }

  .cherry-list__lower-greek {
    list-style: lower-greek;
  }

  .cherry-list__cjk-ideographic {
    list-style: cjk-ideographic;
  }

  .cherry-list__circle {
    list-style: circle;
  }

  .cherry-list__square {
    list-style: square;
  }

  // 浅色系
  [data-code-block-theme='default'] &,
  [data-code-block-theme='funky'] &,
  [data-code-block-theme='solarized-light'] &,
  [data-code-block-theme='coy'] & {
    .cherry-code-block-custom-btn,
    .cherry-copy-code-block,
    .cherry-expand-code-block,
    .cherry-unExpand-code-block,
    .cherry-edit-code-block {
      background-color: #3582fb;
    }
  }

  @keyframes blink {
    0% {
      opacity: 1;
    }
    50% {
      opacity: 0;
    }
    100% {
      opacity: 1;
    }
  }

  .cherry-flow-session-cursor {
    background-color: #3582fb88;
    padding: 0 2.5px;
    animation: blink 1s infinite;
  }
}

.cherry-color-wrap {
  display: none;
  position: fixed;
  width: auto;
  padding: 5px 10px;
  z-index: 6;
  background: #fff;
  box-shadow: $shadow;

  h3 {
    font-size: 12px;
    margin: 0px;
    font-weight: 400;
  }

  [data-toolbar-theme='dark'] & h3 {
    color: $toolbarBtnColorDark;
  }

  .cherry-color-text {
    float: left;
    width: 128px;
    margin: 0 8px 0 5px;
  }

  .cherry-color-bg {
    float: left;
    width: 128px;
    margin-right: 5px;
  }

  .cherry-color-item {
    float: left;
    width: 14px;
    height: 14px;
    border: 1px solid #fff;
    cursor: pointer;

    &:hover {
      border: 1px solid #000;
    }
  }
}

.Cherry-Math {
  svg {
    max-width: 100%;
  }
}

.cherry-suggester-panel {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  background: #fff;
  // border: 1px solid #ccc;
  border-radius: 2px;
  max-height: 500px;
  box-shadow: 0 2px 8px 1px #00000033;
  overflow-x: hidden;
  overflow-y: auto;

  .cherry-suggester-panel__item {
    border: none;
    white-space: nowrap;
    min-width: 50px;
    padding: 5px 13px;
    color: #333;
    display: block;
    cursor: pointer;

    &.cherry-suggester-panel__item--selected {
      background-color: #f2f2f5;
      text-decoration: none;
      color: #eb7350;
    }
    & > i {
      display: inline-block;
      transform: translateY(2px);
      margin-right: 8px;
    }
  }
}

.cherry-suggestion {
  background-color: #ebf3ff;
  color: #3582fb;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
}

.cherry-flex-toc {
  z-index: 11;
  position: absolute;
  width: 160px;
  height: calc(100% - 220px);
  max-height: 600px;
  right: 0;
  top: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #ffffff33;
  margin-right: 8px;
  box-sizing: border-box;
  user-select: none;
  box-shadow: 0px 5px 11px #33333333;
  border-radius: 10px;
  transition: all 0.3s;
  &.cherry-flex-toc__fixed {
    position: fixed;
  }
  &:hover {
    background-color: #fff;
    width: 260px;
  }
  .cherry-toc-head {
    border-bottom: 1px dashed #33333333;
    padding: 5px;
    .cherry-toc-title {
      font-size: 16px;
      font-weight: bold;
      padding-left: 5px;
    }
    .ch-icon-chevronsLeft {
      display: none;
    }
    .ch-icon-chevronsRight,
    .ch-icon-chevronsLeft {
      padding: 5px;
      position: absolute;
      right: 0;
      top: 0;
    }
    i {
      cursor: pointer;
      padding: 5px 5px 0;
      &:hover {
        color: #3582fb;
      }
    }
  }
  .cherry-toc-list {
    overflow-y: auto;
    height: calc(100% - 40px);
    overflow-x: hidden;
    width: 100%;
    padding-bottom: 10px;
    .cherry-toc-one-a {
      display: block;
      text-decoration: none;
      color: #000;
      border-left: 5px solid #33333333;
      height: 28px;
      line-height: 28px;
      transition: all 0.3s;
      padding-left: 10px;
      overflow: hidden;
      word-break: break-all;
      text-overflow: ellipsis;
      cursor: pointer;
      &.current {
        border-left-color: #3582fb;
        color: #3582fb;
      }
      &:hover {
        border-left-color: #3582fbaa;
        color: #3582fbaa;
      }
    }
    .cherry-toc-one-a__1 {
      font-weight: bold;
    }
    .cherry-toc-one-a__2 {
      padding-left: 20px;
    }
    .cherry-toc-one-a__3 {
      padding-left: 40px;
    }
    .cherry-toc-one-a__4 {
      padding-left: 60px;
    }
    .cherry-toc-one-a__5 {
      padding-left: 80px;
    }
  }
  &.cherry-flex-toc__pure {
    width: 30px;
    height: calc(100% - 200px);
    max-height: 600px;
    background: #ffffff00;
    box-shadow: none;
    border-radius: 0;
    .cherry-toc-head {
      height: 25px;
      border-bottom: 1px dashed #33333300;
      .cherry-toc-title {
        display: none;
      }
      .ch-icon-chevronsRight {
        display: none;
      }
      .ch-icon-chevronsLeft {
        display: inline;
      }
    }
    .cherry-toc-list {
      padding-left: 7px;
      .cherry-toc-one-a {
        overflow: hidden;
        width: 0;
        margin-bottom: 3px;
        height: 5px;
        border-left-width: 18px;
      }
    }
  }

  &.auto-num {
    .cherry-toc-list {
      counter-reset: toclevel1;

      .cherry-toc-one-a__1 {
        counter-reset: toclevel2;
      }
      .cherry-toc-one-a__2 {
        counter-reset: toclevel3;
      }
      .cherry-toc-one-a__3 {
        counter-reset: toclevel4;
      }
      .cherry-toc-one-a__4 {
        counter-reset: toclevel5;
      }
      .cherry-toc-one-a__5 {
        counter-reset: toclevel6;
      }
      .cherry-toc-one-a__1:before {
        counter-increment: toclevel1;
        content: counter(toclevel1) '. ';
      }
      .cherry-toc-one-a__2:before {
        counter-increment: toclevel2;
        content: counter(toclevel1) '.' counter(toclevel2) '. ';
      }
      .cherry-toc-one-a__3:before {
        counter-increment: toclevel3;
        content: counter(toclevel1) '.' counter(toclevel2) '.' counter(toclevel3) '. ';
      }
      .cherry-toc-one-a__4:before {
        counter-increment: toclevel4;
        content: counter(toclevel1) '.' counter(toclevel2) '.' counter(toclevel3) '.' counter(toclevel4) '. ';
      }
      .cherry-toc-one-a__5:before {
        counter-increment: toclevel5;
        content: counter(toclevel1) '.' counter(toclevel2) '.' counter(toclevel3) '.' counter(toclevel4) '.'
          counter(toclevel5) '. ';
      }
      .cherry-toc-one-a__6:before {
        counter-increment: toclevel5;
        content: counter(toclevel1) '.' counter(toclevel2) '.' counter(toclevel3) '.' counter(toclevel4) '.'
          counter(toclevel5) '.' counter(toclevel6) '. ';
      }
    }
  }
}

/** 引入自带的主题 */
@import './themes/default.scss';
@import './themes/dark.scss';
@import './themes/light.scss';
@import './themes/green.scss';
@import './themes/red.scss';
@import './themes/violet.scss';
@import './themes/blue.scss';
